package com.zzf.观察者模式;

import java.util.ArrayList;
import java.util.List;

public abstract class Subject {
    //本目标对象的观察者
    private List<Observer> observerList = new ArrayList<>();

    public void addObserver(Observer observer){
        observerList.add(observer);
    }

    public void removeObserver(Observer observer){
        observerList.remove(observer);
    }

    public void notifyAllObservers(Object arg){
        for (Observer observer : observerList){
            observer.update(arg);
        }
    }
}
